import { Controller, Get, Post, Body, Patch, Param, Delete, Query, ParseIntPipe } from "@nestjs/common";
import { PermissionService } from './permission.service';
import { PermissionDto } from "@/modules/permission/dto/dto";

@Controller('permission')
export class PermissionController {
  constructor(private readonly permissionService: PermissionService) {}

  // 创建权限
  @Post('create')
  createPermission(@Body() createPermissionDto: PermissionDto) {
    return this.permissionService.createPermission(createPermissionDto);
  }

  // 获取所有树形列表
  @Get('tree')
  findAllTree() {
    return this.permissionService.findAllTree();
  }

  /* 路由校验 */
  @Get('menu/validate')
  validateMenuPath(@Query('path') path: string) {
    return this.permissionService.validateMenuPath(path);
  }

  // 修改权限
  @Post('update/:id')
  updatePermission(
    @Param('id', ParseIntPipe) id: number,
    @Body() updatePermissionDto: PermissionDto,
  ) {
    return this.permissionService.updatePermission(+id, updatePermissionDto);
  }

  // 删除权限
  @Delete(':id')
  deletePermission(@Param('id', ParseIntPipe) id: number) {
    return this.permissionService.deletePermission(+id);
  }

}
